home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / gdb / gdb_18s.zoo / fake / signal.c < prev   
Encoding:
C/C++ Source or Header  |  1992-03-28  |  1.5 KB  |  76 lines

  1. /*
  2.  *        Cross Development System for Atari ST 
  3.  *     Copyright (c) 1988, Memorial University of Newfoundland
  4.  *
  5.  *   Signal routine - the signals are actually done by calling the _do_signal
  6.  * routine - similiar to kill() I guess.
  7.  *
  8.  * 1.3 ERS added SIGABRT handling, generally fixed up stuff
  9.  * 1.2 ERS added kill, changed _do_signal to an internal function
  10.  *
  11.  */
  12. #include    <signal.h>
  13. #include    <errno.h>
  14. #include    <string.h>
  15. #include    <unistd.h>
  16.  
  17. int __check_signals;            /* used in console i/o routines */
  18. #define    SIG_EXIT    10        /* exit code */
  19.  
  20. struct sigarray_str {
  21.       __Sigfunc s_func;
  22. };
  23. /* SIG_DFL == 0, so everything is implicitly set to this */
  24.  
  25. static struct sigarray_str    sig_array[NSIG] ;
  26.  
  27. void
  28. _init_signal()            /* needed for dumping */
  29. {
  30.     bzero(sig_array, sizeof(sig_array)); /* for now */
  31. }
  32.  
  33. __Sigfunc signal(sig, func)
  34.     int    sig;
  35.       __Sigfunc func;
  36. {
  37.       __Sigfunc oldfunc;
  38.  
  39.     switch (sig) {
  40.     case SIGINT:
  41.     case SIGQUIT:
  42.         if (func != SIG_IGN)
  43.             __check_signals = 1;
  44.     case SIGALRM:
  45.         oldfunc = sig_array[sig].s_func;
  46.         sig_array[sig].s_func = func;
  47.         break;
  48.     default:
  49.         errno = EINVAL;
  50.         oldfunc = SIG_ERR;
  51.     }
  52.     return oldfunc;
  53. }
  54.  
  55. static void
  56. _do_signal(sig)
  57.     int    sig;
  58. {
  59.       __Sigfunc func;
  60.  
  61.     if (sig >= 0 && sig < NSIG) {
  62.         func = sig_array[sig].s_func;
  63.         if (func == SIG_DFL)
  64.             switch (sig) {
  65.             case SIGQUIT:
  66.             case SIGINT:
  67.             case SIGALRM:
  68.                 psignal(sig, "fatal signal received");
  69.                 _exit(SIG_EXIT + sig);
  70.             }
  71.         else if (func != SIG_IGN)
  72.             (*func)(sig);
  73.         /* else ignore it */
  74.     }
  75. }
  76.